<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
         var str1 = 'abcdefg'
         var str2=""
         function fn(str1,str2){
            for(var i=0; i<str1.length;i++){     
            str2+=str1[str1.length-i-1]
                }
                
                console.log(str2)
         }
         fn(str1,str2)
       
    </script>
</body>
</html>